<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<html lang="en">
<head>
    <th:block th:include="include :: header('修改新人注册配置信息')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body  class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-newregister-update" action="updatehome" method="post">
        <div class="col-md-12">
            <input type="hidden">
            <input name="id" type="hidden" th:value="${newRegister.id}" />

            <div class="form-group">
                <input id="details" name="details" type="hidden" th:field="${newRegister.disclaimer}">
                <label class="col-sm-3 control-label">新人注册：</label>
                <div class="col-sm-8">

                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <button id="edit" class="btn btn-primary btn-xs m-l-sm" onclick="editDetails()" type="button">编辑</button>
                            <button id="save" class="btn btn-primary  btn-xs" onclick="saveDetails()" type="button">保存</button>
                        </div>
                        <div class="ibox-content" id="eg">

                            <div class="click2edit wrapper">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12 col-sm-offset-3">
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: summernote-js" />
</body>
<script>
    // var prefix = ctx + "system/shopconfig";
    // function submitHandler() {
    //     if ($.validate.form()) {
    //         console.log(prefix + "/updatehome")
    //         $.operate.save(prefix + "/updatehome", $('#form-homeconfig-update').serialize());
    //     }
    // }

    $(document).ready(function () {
        $('.summernote').summernote({
            lang: 'zh-CN'
        });
    });
    var content = $("#details").val();
    $('.click2edit').summernote('code', content);
    $('.click2edit').summernote('destroy');
    var editDetails = function () {
        $("#eg").addClass("no-padding");
        $('.click2edit').summernote({
            lang: 'zh-CN',
            focus: true,
            callbacks:{
                onImageUpload: function(files) {
                    sendFile(files[0]);
                }
            }
        });
    };
    var saveDetails = function () {
        $("#eg").removeClass("no-padding");
        var aHTML = $('.click2edit').summernote('code');
        $('.click2edit').summernote('destroy');
        $("#details").val(aHTML)
    };

    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_module1'
            , url: '/common/upload' //改成您自己的上传接口
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#show_module1Img").html("<img src='" + res.url + "'>");
                $("#module1Img").val(res.url);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_module2'
            , url: '/common/upload' //改成您自己的上传接口
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#show_module2Img").html("<img src='" + res.url + "'>");
                $("#module2Img").val(res.url);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_shareImg'
            , url: '/common/upload?type=0' //改成您自己的上传接口
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#show_shareImg").html("<img src='" + res.url + "'>");
                $("#shareImg").val(res.url);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })
</script>
</html>